﻿using System;
using System.Web.UI;
using Business;

public partial class Controls_BackEnd_Setting : System.Web.UI.UserControl
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;
        GetData();
    }


    /// <summary>
    /// 
    /// </summary>
    private void GetData()
    {
        Session[SessionManager.SessionControl] = "~/Controls/Common/FileManager.ascx";
        Setting = new Setting().Config_GetByBaner();

    }





    /// <summary>
    /// 
    /// </summary>
    protected Setting Setting
    {
        get
        {
            var setting = (Setting)Session[SessionManager.SessionData] ?? new Setting();
            setting.Banner = txtBanner.Text;
            setting.Logo = txtlogo.Text;
            setting.PageTitle = txtPageTitle.Text;
            setting.HeadTitle = txtHeadTitle.Text;
            setting.Theme = txtTheme.Text;
            setting.Footer = AjaxEditor1.Content;
            setting.Email = txtEmail.Text;
            setting.Password = txtpass.Text;
            setting.SMTP = txtSMTP.Text;
            setting.SSL = cbSSL.Checked;
            setting.Pop3 = txtPop.Text;
            int port;
            int.TryParse(txtPort.Text, out port);
            setting.Port = port;
            return setting;
        }
        set
        {
            Session[SessionManager.SessionData] = value;
            txtBanner.Text = value.Banner;
            txtlogo.Text = value.Logo;
            txtHeadTitle.Text = value.HeadTitle;
            txtPageTitle.Text = value.PageTitle;
            txtTheme.Text = value.Theme;
            AjaxEditor1.Content = value.Footer;
            lblUsername.Text = value.Username;
            txtEmail.Text = value.Email;
            txtpass.Text = value.Password;
            txtSMTP.Text = value.SMTP;
            cbSSL.Checked = value.SSL;
            txtPop.Text = value.Pop3;
            txtPort.Text = value.Port.ToString();
        }
    }









    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AllCommand(object sender, EventArgs e)
    {
        switch (((Control)sender).ID)
        {
            case "btnSave":
                var error = Setting.Save();
                if (error > 0)
                {
                    Config.Message(Page, Resources.Resource.SaveSuccess, Resources.Resource.Messenger);
                    return;
                }
                break;

        }

    }


}



